<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">

      <el-form-item label="检验时间" prop="inspectTime">
        <el-date-picker clearable v-model="queryParams.inspectTime"
                        type="date" value-format="yyyy-MM-dd" placeholder="请选择检验时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" type="index"  width="55" align="center"/>
      <el-table-column label="检验时间" align="center" prop="inspectTime" width="180">
        <template slot-scope="scope">
          <el-date-picker clearable v-model="scope.row.inspectTime" type="datetime" value-format="yyyy-MM-dd"
                          placeholder="请选择检验时间">
          </el-date-picker>
        </template>
      </el-table-column>
      <el-table-column prop="znThick" label="锌层厚度" width="150">
        <template slot-scope="scope">
          <el-input-number size="mini" v-model="scope.row.znThick"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" width="150">
        <template slot-scope="scope">
          <el-input size="mini" v-model="scope.row.dun"></el-input>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryTestZnDetail:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:FactoryTestZnDetail:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="okSure">确 定</el-button>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>
    <factoryTestZnDetail-form ref="form" @ok="getList"></factoryTestZnDetail-form>
  </el-dialog>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import FactoryTestZnDetailForm from '@/views/develop/factory/factoryTestZnDetail/module/FactoryTestZnDetailForm'
import FileUploadShow from "@/components/FileUpload/FileUploadShow.vue";

export default {
  name: "FactoryTestZnDetailFormListModule",
  components: {
    FileUploadShow,
    FactoryTestZnDetailForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      open: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      testId: null,
      // 出厂试验-镀锌质量-每次明细表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        testId: null,
        inspectTime: null,
        znThick: null,
        reportFile: null,
        pictureFile: null,
      },
      url: {
        list: '/factoryTestZnDetail/factoryTestZnDetail/list',
        remove: '/factoryTestZnDetail/factoryTestZnDetail/',
        export: '/factoryTestZnDetail/factoryTestZnDetail/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {

    show(row){
      this.open=true;
      this.title="检测记录";
      this.testId=row.id;
      this.queryParams.testId = row.id;
      this.getList();
    },

    /** 查询出厂试验-镀锌质量-每次明细列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAddByTestId(this.testId);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `factoryTestZnDetail_${new Date().getTime()}.xlsx`)
    },

    okSure(){
      this.open = false;
      this.$emit('ok');
    }
  }
};
</script>
